package com.zrf.gulimall.search.controller;

import com.zrf.gulimall.search.service.MallSearchService;
import com.zrf.gulimall.search.vo.SearchParam;
import com.zrf.gulimall.search.vo.SearchResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * @Author zhanrf
 * @Date 2021/12/24 0:49
 */
@Controller
public class SearchController {
	@Autowired
	private MallSearchService mallSearchService;

	@GetMapping("/list.html")
	public String list(SearchParam searchParam, Model model, HttpServletRequest request) throws IOException {
		searchParam.set_queryString(request.getQueryString());
		SearchResult searchResult = mallSearchService.search(searchParam);
		model.addAttribute("result", searchResult);
		return "list";
	}
}
